package com.liliya.servlet.pro;

import com.liliya.pojo.Pro;
import com.liliya.service.ProService;
import com.liliya.service.impl.ProServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Description 商品搜索
 * @Author hhy
 * @Date 2021/1/14 19:00
 */
@WebServlet(urlPatterns = "/pro/search")
public class ProSearchServlet extends HttpServlet {
    private ProService proService = new ProServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<String> columns = proService.findColumnName();
        System.out.println(columns);
        req.setAttribute("columns",columns);
        req.getRequestDispatcher("./prosearch.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String searchname = req.getParameter("searchname");
        String searchvalue = req.getParameter("searchvalue");
        Pro pro = proService.findPro(searchname, searchvalue);

        req.setAttribute("pro",pro);
        req.getRequestDispatcher("./prosearchresult.jsp").forward(req,resp);
    }
}
